/**
 * 构造HTML5元素集合
 */
const makeEleMap = (eleStr = '') => {
  let eleStrArr = eleStr.split(',');
  let eleObj = {};
  eleStrArr.forEach(v => {
    eleObj[v] = v;
  });
  return new Map(Object.entries(eleObj));
}
/**
 * HTML5 元素集合
 */
// 块级元素 - HTML 5
let blockEleMap = makeEleMap("body,br,code,address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video");
// 行间元素 - HTML 5
let inlineEleMap = makeEleMap("a,abbr,acronym,applet,b,basefont,bdo,big,button,cite,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");
// 可自闭合元素
let closeSelfEleMap = makeEleMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
// 一元元素
let emptyEleMap = makeEleMap("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed");

/**
 * 字符串匹配正则规则
 */
const startTagReg = /^<([A-Za-z_-]+)((?:\s*[A-Za-z_:][-A-Za-z_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/; // 开始标签
const endTagReg = /^<\/([-A-Za-z0-9_]+)[^>]*>/; // 结束标签

// 模拟基础html5标签样式
const tagBaseStyleMap = new Map([
['button', { display: 'inline-block' }],
['textarea', { display: 'inline-block' }],
['input', { display: 'inline-block' }],
['object', { display: 'inline-block' }],
['select', { display: 'inline-block' }],
['ol',
  {
    'margin-left': '40px',
    'list-style-type': 'decimal',
    'margin-top': '0',
    'margin-bottom': '0',
    margin: '1.12em 0'
  }],
['ul',
  {
    'margin-left': '40px',
    'margin-top': '0',
    'margin-bottom': '0',
    margin: '1.12em 0'
  }],
['dir',
  { 'margin-left': '40px', display: 'block', margin: '1.12em 0' }],
['menu',
  { 'margin-left': '40px', display: 'block', margin: '1.12em 0' }],
['dd', { 'margin-left': '40px', display: 'block' }],
['i', { 'font-style': 'italic' }],
['cite', { 'font-style': 'italic' }],
['em', { 'font-style': 'italic' }],
['var', { 'font-style': 'italic' }],
['address', { 'font-style': 'italic', display: 'block' }],
['blockquote',
  {
    display: 'block',
    margin: '1.12em 0',
    'margin-left': '40px',
    'margin-right': '40px'
  }],
['form', { display: 'block', margin: '1.12em 0' }],
['dl', { display: 'block', margin: '1.12em 0' }],
['dt', { display: 'block' }],
['fieldset', { display: 'block', margin: '1.12em 0' }],
['frame', { display: 'block' }],
['frameset', { display: 'block' }],
['noframes', { display: 'block' }],
['center', { display: 'block', 'text-align': 'center' }],
['hr', { display: 'block', border: '1px inset' }],
['pre',
  {
    display: 'block',
    'font-family': 'monospace',
    'white-space': 'pre'
  }],
['li', { display: 'list-item' }],
['h1',
  {
    'font-size': '2em',
    margin: '.67em 0',
    'font-weight': 'bolder'
  }],
['h2',
  {
    'font-size': '1.5em',
    margin: '.75em 0',
    'font-weight': 'bolder'
  }],
['h3',
  {
    'font-size': '1.17em',
    margin: '.83em 0',
    'font-weight': 'bolder'
  }],
['h4', { margin: '1.12em 0', 'font-weight': 'bolder' }],
// ['p', { margin: '1.12em 0' }],
['h5',
  {
    'font-size': '.83em',
    margin: '1.5em 0',
    'font-weight': 'bolder'
  }],
['h6',
  {
    'font-size': '.75em',
    margin: '1.67em 0',
    'font-weight': 'bolder'
  }],
['b', { 'font-weight': 'bolder' }],
['strong', { 'font-weight': 'bolder' }],
['table', { display: 'table', 'border-spacing': '2px' }],
['tr', { display: 'table-row' }],
['thead',
  { display: 'table-header-group', 'vertical-align': 'middle' }],
['tbody',
  { display: 'table-row-group', 'vertical-align': 'middle' }],
['tfoot',
  { display: 'table-footer-group', 'vertical-align': 'middle' }],
['col', { display: 'table-column' }],
['colgroup', { display: 'table-column-group' }],
['td', { display: 'table-cell', 'vertical-align': 'inherit' }],
['th',
  {
    display: 'table-cell',
    'font-weight': 'bolder',
    'text-align': 'center',
    'vertical-align': 'inherit'
  }],
['caption',
  { display: 'table-caption', 'text-align': 'center' }],
['tt', { 'font-family': 'monospace' }],
['code', { 'font-family': 'monospace' }],
['kbd', { 'font-family': 'monospace' }],
['samp', { 'font-family': 'monospace' }],
['big', { 'font-size': '1.17em' }],
['small', { 'font-size': '.83em' }],
['sub', { 'font-size': '.83em', 'vertical-align': 'sub' }],
['sup', { 'font-size': '.83em', 'vertical-align': 'super' }],
['s', { 'text-decoration': 'line-through' }],
['strike', { 'text-decoration': 'line-through' }],
['del', { 'text-decoration': 'line-through' }],
['u', { 'text-decoration': 'underline' }],
['ins', { 'text-decoration': 'underline' }],
['abbr',
  { 'font-variant': 'small-caps', 'letter-spacing': '0.1em' }],
['acronym',
  { 'font-variant': 'small-caps', 'letter-spacing': '0.1em' }]]);

module.exports = {
  blockEleMap,
  inlineEleMap,
  closeSelfEleMap,
  emptyEleMap,
  startTagReg,
  endTagReg,
  tagBaseStyleMap
}